/*
 *  Computer Graphics:  Andrew Hanson
 * GLUT RGB  Graphics template 
 *

 cc -o glut.linux glut.c  -lglut -lGLU -lGL  -lm


 NOTE: This should work on default-X-configured Linux GRAPHICS SERVERS
        because it defines an RGB visual. 

 *
 *
 */


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>

/* Local Graphics Definitions  */
#include "defs.h"


/***************************************************************/
/******************** MY GLOBAL VARIABLES **********************/
/***************************************************************/

int mouseButtons = 0;

int MouseModifiers = 0;

int  X=0, Y=0, dX=0, dY=0;
GLfloat XC = 0.0, YC = 0.0, ZC = -10.0;
int main_window;
int main_height, main_width;




/***************************************************************/
/************************** INIT GL ****************************/
/***************************************************************/


void
initGL()
{
	glColor3f(1.0,1.0,0.0);
	  glLineWidth(3.0);
  glClearColor(0.0,0.0,1.0,0.0);
  //glColor3f(0.0f, 0.0f, 0.0f);
  glEnable(GL_DEPTH_TEST);
  glPointSize(4.0);
}




/***************************************************************/
/************************ DRAW STUFF ***************************/
/***************************************************************/

 

struct Point {
		GLint x,y;
};

void 
drawDot(GLint x, GLint y){
	printf("Points %d,%d", x, y);
	glBegin(GL_POINTS);
	glVertex2i(x,y);
	glEnd();
	glFlush();
}

void
drawObjs()
{
	struct Point points[3] = {  {10,10}, {300,30}, {200,300}}; 
	int index = rand() %3;
	struct Point point = points[index];
	drawDot(point.x, point.y);
	
	int i;
	for(i = 0; i < 1000; i++){
		index = rand() % 3;
		point.x = (point.x + points[index].x)/2;
		point.y = (point.y + points[index].y)/2;
		drawDot(point.x, point.y);
	}
	glFlush();
}

void
display(void)
{
  fprintf(stderr,"Comment this out: display\n");

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  /* glClear(GL_COLOR_BUFFER_BIT); */

  
  glBegin(GL_LINE);
  glVertex2f(100,100);
  glVertex2f(400,400);
  glEnd();
  
  drawObjs();

  glutSwapBuffers();
}


/***************************************************************/
/**************************** MAIN *****************************/
/***************************************************************/


int
main(int argc, char **argv)
{
  /* GLUT Initialization */
  glutInit(&argc,argv);
  glutInitWindowSize(640, 480);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA |GLUT_DEPTH);

  /* Create a new window and give a title to it */
  main_window = glutCreateWindow("CHANGE THIS TITLE!!!!!!!");

  /* Initialize OpenGL stuff */
  initGL();

  glutDisplayFunc(display);
  
  glutIdleFunc(NULL);

  glutMainLoop();

  return(EXIT_SUCCESS);
}
